﻿<UserControl x:Class="NexTrackDesktop.Controls.MediaLibraryTab"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:MetroControls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
             mc:Ignorable="d" 
             d:DesignHeight="485" d:DesignWidth="651">
    
    <UserControl.Resources>
        <Style TargetType="ListView">
            <Setter Property="AlternationCount" Value="2" />
        </Style>

        <Style TargetType="ListViewItem">
            <Setter Property="IsSelected" Value="{Binding Mode=TwoWay, Path=Selected, UpdateSourceTrigger=PropertyChanged}"/>
        </Style>

    </UserControl.Resources> 
    
    <Grid>
        <!--Split view into 3 piece view-->
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="51*" />
            <ColumnDefinition Width="49*" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="51*" />
            <RowDefinition Height="49*" />
            <RowDefinition Height="auto" />
        </Grid.RowDefinitions>
        <!--Splitter used for resizing-->
        <GridSplitter Width="3" Height="Auto" HorizontalAlignment="Right" VerticalAlignment="Stretch" ResizeDirection="Columns" />
        <GridSplitter Grid.ColumnSpan="2" Width="Auto" Height="3" HorizontalAlignment="Stretch" VerticalAlignment="Bottom" ResizeDirection="Rows" />
        
        <!--Library sorted by Artist-->
        <ListView Margin="0,0,3,3" ItemsSource="{Binding Artists}" VirtualizingStackPanel.IsVirtualizing="False">
            <ListView.View>
                <GridView>
                    <!--Columns used for Song info-->
                    <GridView.Columns>
                        <GridViewColumn Header="Artist" Width="200" DisplayMemberBinding="{Binding Path=Name}" />
                        <GridViewColumn Header="Albums" Width="60" DisplayMemberBinding="{Binding Path=NumberAlbums}" />
                        <GridViewColumn Header="Tracks" Width="65" DisplayMemberBinding="{Binding Path=NumberTracks}" />
                    </GridView.Columns>
                </GridView>
            </ListView.View>
        </ListView>
        
        <!--Library sorted by Album-->
        <ListView Grid.Column="1" Margin="0,0,0,3" ItemsSource="{Binding Albums}" VirtualizingStackPanel.IsVirtualizing="False">
            <ListView.View>
                <GridView>
                    <!--Columns used for Song info-->
                    <GridView.Columns>
                        <GridViewColumn Header="Album" Width="200" DisplayMemberBinding="{Binding Path=Title}"/>
                        <GridViewColumn Header="Tracks" Width="65" DisplayMemberBinding="{Binding Path=NumberTracks}"/>
                    </GridView.Columns>
                </GridView>
            </ListView.View>
        </ListView>
        
        <!-- Songs List -->
        <ListView Grid.Row="1" Grid.ColumnSpan="2" ItemsSource="{Binding Songs}" VirtualizingStackPanel.IsVirtualizing="False">
            <ListView.View>
                <GridView>
                    <!--Columns used for Song info-->
                    <GridView.Columns>
                        <GridViewColumn Header="Artist" Width="150" DisplayMemberBinding="{Binding Path=Song.Artist}" />
                        <GridViewColumn Header="Album" Width="150" DisplayMemberBinding="{Binding Path=Song.Album}" />
                        <GridViewColumn Header="Title" Width="250" DisplayMemberBinding="{Binding Path=Song.Title}" />
                        <GridViewColumn Header="Length" Width="65" DisplayMemberBinding="{Binding Path=Song.Length,StringFormat={}{0:mm':'ss}}" />
                    </GridView.Columns>
                </GridView>
            </ListView.View>
            
            <ListView.ContextMenu>
                <ContextMenu>
                    <MenuItem Header="Force Play"
                              Command="{Binding ForcePlaySong}"/>
                </ContextMenu>
            </ListView.ContextMenu>
        </ListView>
        
        <!--Includes Search box, Add to Playlist and Manage Library buttons-->
        <DockPanel Grid.Row="2" Grid.ColumnSpan="2" Margin="0,4,0,0">
            <Menu DockPanel.Dock="Right" VerticalContentAlignment="Center">

                <MenuItem Header="Reset Filter" Command="{Binding ResetFilterCommand}"/>
                
                <MenuItem Header="Add to Playlist" Command="{Binding AddToPlaylistCommand}"/>

                <MenuItem Header="Manage Library" HorizontalAlignment="Right">
                    <MenuItem Header="Add Media from folder..." Command="{Binding AddFolderCommand}"/>
                    <MenuItem Header="Add Media..." Command="{Binding AddMediaCommand}"/>
                    <MenuItem Header="Remove Media" Command="{Binding RemoveMediaCommand}" />
                </MenuItem>
                
            </Menu>
        </DockPanel>
    </Grid>
</UserControl>
